﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECONTACT.Bussiness;
using ECONTACT.DataLayer;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors.DateTimeAdv;

namespace ECONTACT.Controller
{
    public class LopCtrl
    {
        LopData m_LopData = new LopData();

        #region Hien thi ComboBox
        public void HienThiComboBox(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_LopData.LayDsLop();
            comboBox.DisplayMember = "MaLop";
            comboBox.ValueMember = "MaLop";
        }

        public void HienThiComboBoxTen(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_LopData.LayDsLop();
            comboBox.DisplayMember = "Ten";
            comboBox.ValueMember = "MaLop";
        }
        #endregion

        #region Do du lieu vao DataGridView

        public void HienThi(DataGridViewX dGV,
                            TextBoxX txtMaLop,
                            TextBoxX txtTen,
                            ComboBoxEx cmbMaKhoiLop,
                            ComboBoxEx cmbMaNamHoc,
                            ComboBoxEx cmbMaGV)
        {
            BindingSource bS = new BindingSource();
            bS.DataSource = m_LopData.LayDsLop();

            DataTable dT = m_LopData.LayDsLop();

            txtMaLop.DataBindings.Clear();
            txtMaLop.DataBindings.Add("Text", bS, "MaLop");

            txtTen.DataBindings.Clear();
            txtTen.DataBindings.Add("Text", bS, "Ten");

            cmbMaKhoiLop.DataBindings.Clear();
            cmbMaKhoiLop.DataBindings.Add("SelectedValue", bS, "MaKhoiLop");

            cmbMaNamHoc.DataBindings.Clear();
            cmbMaNamHoc.DataBindings.Add("SelectedValue", bS, "MaNamHoc");

            cmbMaGV.DataBindings.Clear();
            cmbMaGV.DataBindings.Add("SelectedValue", bS, "MaGV");

            //bN.BindingSource = bS;
            dGV.DataSource = bS;
        }
        #endregion

        public void LuuLop(String Ten, String MaKhoiLop, String MaNamHoc, String MaGV)
        {
            m_LopData.LuuLop(Ten, MaKhoiLop, MaNamHoc, MaGV);
        }

        public void UpdateLop(String MaLop, String Ten, String MaKhoiLop, String MaNamHoc, String MaGV)
        {
            m_LopData.UpdateLop(MaLop, Ten, MaKhoiLop, MaNamHoc, MaGV);
        }

        public void DeleteLop(String MaLop)
        {
            m_LopData.DeleteLop(MaLop);
        }
    }
}
